package com.gettagger.tagger.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;

import com.gettagger.tagger.R;

public class ActMain extends Activity {

	private ImageView btnScan;
	private ImageView btnAccount;
	private ImageView btnHelp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.act_main);

		btnScan = (ImageView) findViewById(R.id.main_iv_scan);
		btnScan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Intent intent = new
				// Intent(ActMain.this,CaptureActivity.class);
				Intent intent = new Intent("com.google.zxing.client.android.SCAN");

				intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
				startActivityForResult(intent, 0);

			}
		});

		btnAccount = (ImageView) findViewById(R.id.main_iv_account);
		btnAccount.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ActMain.this,ActUserInfo.class);
				startActivity(intent);
			}
		});

		btnHelp = (ImageView) findViewById(R.id.main_iv_help);
		btnHelp.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(ActMain.this, "Function not yet available", Toast.LENGTH_SHORT).show();
			}
		});
	}

	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				String contents = intent.getStringExtra("SCAN_RESULT");
				String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

				if (format.equals("QR_CODE")) {

					Intent intent1 = new Intent(this, ActDetails.class);
					intent1.putExtra("DETAILS", contents);
					startActivity(intent1);

				} else {
					Toast.makeText(this, "Invalid Format.", Toast.LENGTH_SHORT).show();
				}
				Log.i("xZing", "contents: " + contents + " format: " + format);
			}
		}

	}

}
